{"record":{"id":"56923ad79f3fa303","repo":"python/cpython","slug":"lineno-must-be-an-int","errorCode":null,"errorMessage":"lineno must be an int","messagePattern":"lineno must be an int","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"Lib/_py_warnings.py","lineNumber":275,"sourceCode":"\n    'action' -- one of \"error\", \"ignore\", \"always\", \"all\", \"default\", \"module\",\n                or \"once\"\n    'message' -- a regex that the warning message must match\n    'category' -- a class that the warning must be a subclass of\n    'module' -- a regex that the module name must match\n    'lineno' -- an integer line number, 0 matches all warnings\n    'append' -- if true, append to the list of filters\n    \"\"\"\n    if action not in {\"error\", \"ignore\", \"always\", \"all\", \"default\", \"module\", \"once\"}:\n        raise ValueError(f\"invalid action: {action!r}\")\n    if not isinstance(message, str):\n        raise TypeError(\"message must be a string\")\n    if not isinstance(category, type) or not issubclass(category, Warning):\n        raise TypeError(\"category must be a Warning subclass\")\n    if not isinstance(module, str):\n        raise TypeError(\"module must be a string\")\n    if not isinstance(lineno, int):\n        raise TypeError(\"lineno must be an int\")\n    if lineno < 0:\n        raise ValueError(\"lineno must be an int >= 0\")\n\n    if message or module:\n        import re\n\n    if message:\n        message = re.compile(message, re.I)\n    else:\n        message = None\n    if module:\n        module = re.compile(module)\n    else:\n        module = None\n\n    _wm._add_filter(action, message, category, module, lineno, append=append)\n\n","sourceCodeStart":257,"sourceCodeEnd":293,"githubUrl":"https://github.com/python/cpython/blob/bc6749cc3b5ae4a5e88a6cc2d5b3bebbe354eae6/Lib/_py_warnings.py#L257-L293","documentation":"Raised by warnings.filterwarnings when lineno is not an int. The filter tuple stores a plain integer line number (0 matches all lines); strings like '42', floats, or None are rejected with TypeError('lineno must be an int'). Note bool passes isinstance(x, int) but 0/False and True/1 mean lines all and 1 respectively.","triggerScenarios":"warnings.filterwarnings('ignore', lineno='3'); lineno=None; lineno=3.0; lineno read from a config file as a string and forwarded unconverted.","commonSituations":"Config/CLI-driven warning filters where values arrive as strings; JSON/YAML settings parsed into strings; None used to mean 'any line' instead of 0.","solutions":["Pass an int: lineno=3, or 0 to match all lines","Coerce config values: lineno=int(raw) at parse time","Use 0 (the default) instead of None for 'any line'"],"exampleFix":"# before\nwarnings.filterwarnings('ignore', lineno=config['line'])  # '3' from JSON -> TypeError\n\n# after\nwarnings.filterwarnings('ignore', lineno=int(config['line']))","handlingStrategy":"type-guard","validationCode":"def as_lineno(value) -> int:\n    if value is None:\n        return 0\n    if isinstance(value, bool) or not isinstance(value, int):\n        raise TypeError(f'lineno must be int, got {type(value).__name__}')\n    return value\n\nimport warnings\nwarnings.filterwarnings('ignore', lineno=as_lineno(raw))","typeGuard":"def is_plain_int(v) -> bool:\n    return isinstance(v, int) and not isinstance(v, bool)","tryCatchPattern":null,"preventionTips":["Coerce config/CLI values with int(...) at the boundary","Use 0 for 'any line'; never None","Remember bools pass isinstance(x, int) — exclude them explicitly if they can occur"],"tags":["warnings","validation","lineno","filters"],"backgroundTag":null,"analyzedSha":"bc6749cc3b5ae4a5e88a6cc2d5b3bebbe354eae6","analyzedAt":"2026-08-14T22:01:13.976Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}