{"record":{"id":"3b92ee0d95231c61","repo":"python-telegram-bot/python-telegram-bot","slug":"positional-passing-of-filename-or-keyword-usage","errorCode":null,"errorMessage":"Positional passing of `filename` or keyword usage of `filename_depr` is deprecated. `filename` will become a keyword-only argument.","messagePattern":"Positional passing of `filename` or keyword usage of `filename_depr` is deprecated\\. `filename` will become a keyword-only argument\\.","errorType":"console","errorClass":"PTBDeprecationWarning","httpStatus":null,"severity":"warning","filePath":"src/telegram/_files/inputmedia.py","lineNumber":510,"sourceCode":"        parse_mode: ODVInput[str] = DEFAULT_NONE,\n        width: int | None = None,\n        height: int | None = None,\n        duration: TimePeriod | None = None,\n        caption_entities: Sequence[MessageEntity] | None = None,\n        # tag: deprecated 22.8\n        filename_depr: str | None = None,\n        # -\n        has_spoiler: bool | None = None,\n        thumbnail: \"FileInput | None\" = None,\n        show_caption_above_media: bool | None = None,\n        *,\n        filename: str | None = None,\n        api_kwargs: JSONDict | None = None,\n    ):\n        if filename_depr is not None and filename is not None:\n            raise ValueError(\"`filename_depr` and `filename` are mutually exclusive.\")\n        if filename_depr is not None:\n            warn(\n                PTBDeprecationWarning(\n                    \"22.8\",\n                    \"Positional passing of `filename` or keyword usage of `filename_depr`\"\n                    \" is deprecated. `filename` will become a keyword-only argument.\",\n                ),\n                stacklevel=2,\n            )\n\n        if isinstance(media, Animation):\n            width = media.width if width is None else width\n            height = media.height if height is None else height\n            duration = duration if duration is not None else media._duration\n            media = media.file_id\n        else:\n            # We use local_mode=True because we don't have access to the actual setting and want\n            # things to work in local mode.\n            effective_filename = filename_depr or filename\n            media = parse_file_input(","sourceCodeStart":492,"sourceCodeEnd":528,"githubUrl":"https://github.com/python-telegram-bot/python-telegram-bot/blob/d3b69d2e9fb7af6c796f84516cfda751752c7cb7/src/telegram/_files/inputmedia.py#L492-L528","documentation":"InputMediaAnimation.__init__ emits a PTBDeprecationWarning (since v22.8) when filename is passed via the deprecated filename_depr keyword or positionally. filename is becoming keyword-only; the warning tells you to update the call.","triggerScenarios":"Constructing InputMediaAnimation(..., filename_depr='a.gif') or passing filename as a positional argument.","commonSituations":"Old tutorials or codebases written against PTB < 22.8 where filename was accepted differently; CI runs with -W error turning warnings into failures.","solutions":["Replace filename_depr='x' with keyword filename='x'","Pass filename only as a keyword argument, never positionally","Run tests with warnings visible to catch remaining usages"],"exampleFix":"# before\nmedia = InputMediaAnimation(fileobj, 'anim.gif')\n# or InputMediaAnimation(fileobj, filename_depr='anim.gif')\n# after\nmedia = InputMediaAnimation(fileobj, filename='anim.gif')","handlingStrategy":"validation","validationCode":"assert 'filename_depr' not in kwargs and len([a for a in args if isinstance(a, str)]) == 0","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Pass filename as a keyword only","Run pytest with -W error::telegram.warnings.PTBDeprecationWarning to catch regressions","grep for filename_depr during upgrades"],"tags":["python","telegram-bot","deprecation","inputmedia"],"backgroundTag":"deprecated-argument","analyzedSha":"d3b69d2e9fb7af6c796f84516cfda751752c7cb7","analyzedAt":"2026-08-28T16:18:54.805Z","schemaVersion":2},"datasetVersion":"2026-08-28T21:17:43.275Z"}