typing_copilot icon indicating copy to clipboard operation
typing_copilot copied to clipboard

union-attr mypy error reported in strict run, but not in laxest configuration

Open cpennington opened this issue 4 years ago • 6 comments

Validation failed due to unexpected error(s):
[MypyError(file_path='auto_to.py', line_number=1370, error_code='union-attr', message='error: Item "None" of "Optional[datetime]" has no attribute "astimezone"'),
 MypyError(file_path='auto_to.py', line_number=1453, error_code='union-attr', message='error: Item "None" of "Optional[datetime]" has no attribute "astimezone"')]

This is with mypy 0.800 in python 3.9.

cpennington avatar Feb 15 '21 12:02 cpennington

The particular issue was lambda v: dateparser.parse(v).astimezone(). In this case, .parse(v) returns an Optional[datetime].

cpennington avatar Feb 15 '21 13:02 cpennington

Thanks for reporting this, it is definitely a bug.

Action items for me:

  • [ ] Attempt to reproduce the error on my machine. Thank you for sharing the particular Python code that was causing the issue -- that will certainly make it easier.
  • [ ] Improve the error message. I originally expected it should be unreachable, but clearly there are situations where mypy doesn't report all issues the first time around (perhaps because some mypy issue concealed another?), which means that typing_copilot's validation pass will be the first place where those mypy issues come up.
  • [ ] Try to figure out why typing_copilot's "baseline config" pass doesn't catch this error, and what can be done about it. Per the mypy documentation the union-attr check should be always enabled by default, but clearly that error didn't come up in the "baseline" pass in your code. I'd like to make it either come up in the baseline pass, or be able to be suppressed in the generated mypy config.

Two questions for you:

  • I'd like to verify that this was not a blocking issue for your use case. By the looks of it, mypy is correct about the type error on that code, and since it seems there were only two instances, I'm hoping you were able to address them and still adopt typing_copilot -- is that right?
  • If you have a moment, could you re-run typing_copilot with --verbose and share the output if possible? That will help me verify a couple of assumptions, like the one about the union-attr error only coming up during the validation pass and not at any prior time.

obi1kenobi avatar Feb 15 '21 16:02 obi1kenobi

Yeah, it was easy enough to fix the lines in question. I'll reindtroduce the bug and run with verbose.

Maybe relevant: this was in a decorator argument.

cpennington avatar Feb 15 '21 19:02 cpennington


Verbose mode enabled.
A mypy.ini file already exists, and will be overwritten since '--overwrite' was set.

Running mypy once with laxest settings to establish a baseline. Please wait...

Writing temporary mypy config file:


# Autogenerated by typing_copilot v0.5.4
[mypy]
no_implicit_optional = False
strict_optional = False
warn_redundant_casts = False
check_untyped_defs = False
disallow_untyped_calls = False
disallow_incomplete_defs = False
disallow_untyped_defs = False
disallow_untyped_decorators = False
ignore_missing_imports = True
warn_unused_ignores = False


Running mypy with ['mypy', '--config-file', '/tmp/mypy-copilot-ur3x9vk_/mypy.ini', '--show-error-codes', '--error-summary', '.']
Run completed with exit code 0. Stdout: ***
Success: no issues found in 8 source files

***
Collecting mypy errors from strictest check configuration. Please wait...

Writing temporary mypy config file:


# Autogenerated by typing_copilot v0.5.4
[mypy]
no_implicit_optional = True
strict_optional = True
warn_redundant_casts = True
check_untyped_defs = True
disallow_untyped_calls = True
disallow_incomplete_defs = True
disallow_untyped_defs = True
disallow_untyped_decorators = True
ignore_missing_imports = False
warn_unused_ignores = False


Running mypy with ['mypy', '--config-file', '/tmp/mypy-copilot-xw7cpv04/mypy.ini', '--show-error-codes', '--error-summary', '.']
Run completed with exit code 1. Stdout: ***
setup.py:3: error: Skipping analyzing 'setuptools': found module but no type hints or library stubs  [import]
notify.py:1: error: Cannot find implementation or library stub for module named 'notify2'  [import]
notify.py:4: error: Function is missing a return type annotation  [no-untyped-def]
notify.py:4: note: Use "-> None" if function does not return a value
notify.py:9: error: Function is missing a type annotation  [no-untyped-def]
gcal.py:3: error: Skipping analyzing 'httplib2': found module but no type hints or library stubs  [import]
gcal.py:8: error: Skipping analyzing 'apiclient': found module but no type hints or library stubs  [import]
gcal.py:9: error: Skipping analyzing 'oauth2client': found module but no type hints or library stubs  [import]
gcal.py:11: error: Skipping analyzing 'oauth2client.file': found module but no type hints or library stubs  [import]
gcal.py:37: error: Function is missing a type annotation  [no-untyped-def]
gcal.py:40: error: Function is missing a type annotation  [no-untyped-def]
gcal.py:41: error: Unsupported target for indexed assignment ("Mapping[str, str]")  [index]
gcal.py:45: error: Function is missing a type annotation  [no-untyped-def]
gcal.py:55: error: Function is missing a type annotation  [no-untyped-def]
gcal.py:57: error: Call to untyped function "Flags" in typed context  [no-untyped-call]
gcal.py:59: error: Function is missing a return type annotation  [no-untyped-def]
gcal.py:83: error: Function is missing a type annotation  [no-untyped-def]
gcal.py:96: error: Function is missing a return type annotation  [no-untyped-def]
gcal.py:97: error: Call to untyped function "get_credentials" in typed context  [no-untyped-call]
gcal.py:101: error: Function is missing a type annotation  [no-untyped-def]
gcal.py:104: error: Call to untyped function "event_body" in typed context  [no-untyped-call]
gcal.py:109: error: Function is missing a type annotation  [no-untyped-def]
gcal.py:115: error: Call to untyped function "event_body" in typed context  [no-untyped-call]
autoto/db.py:2: error: Skipping analyzing 'dataset': found module but no type hints or library stubs  [import]
autoto/db.py:52: error: Function is missing a type annotation  [no-untyped-def]
autoto/db.py:58: error: Function is missing a type annotation  [no-untyped-def]
autoto/db.py:62: error: Function is missing a type annotation  [no-untyped-def]
autoto/db.py:66: error: Function is missing a type annotation  [no-untyped-def]
autoto/db.py:73: error: Call to untyped function "remove_marker" in typed context  [no-untyped-call]
autoto/db.py:74: error: Call to untyped function "default_title" in typed context  [no-untyped-call]
autoto/db.py:76: error: Call to untyped function "remove_marker" in typed context  [no-untyped-call]
autoto/db.py:77: error: Call to untyped function "default_body" in typed context  [no-untyped-call]
autoto/challonge.py:3: error: Skipping analyzing 'challonge': found module but no type hints or library stubs  [import]
autoto/challonge.py:3: note: See https://mypy.readthedocs.io/en/latest/running_mypy.html#missing-imports
autoto/challonge.py:5: error: Skipping analyzing 'lazy': found module but no type hints or library stubs  [import]
autoto/challonge.py:11: error: Function is missing a type annotation  [no-untyped-def]
autoto/challonge.py:17: error: Need type annotation for 'data'  [var-annotated]
autoto/challonge.py:20: error: Function is missing a return type annotation  [no-untyped-def]
autoto/challonge.py:27: error: Function is missing a return type annotation  [no-untyped-def]
autoto/challonge.py:31: error: Function is missing a return type annotation  [no-untyped-def]
autoto/challonge.py:42: error: Function is missing a type annotation  [no-untyped-def]
autoto/challonge.py:48: error: Function is missing a return type annotation  [no-untyped-def]
autoto/challonge.py:52: error: Function is missing a return type annotation  [no-untyped-def]
autoto/challonge.py:79: error: Function is missing a return type annotation  [no-untyped-def]
autoto/challonge.py:106: error: Function is missing a return type annotation  [no-untyped-def]
autoto/challonge.py:107: error: Call to untyped function "on_day" in typed context  [no-untyped-call]
autoto/challonge.py:142: error: Argument "key" to "sorted" has incompatible type overloaded function; expected "Callable[[Any], SupportsLessThan]"  [arg-type]
autoto/challonge.py:151: error: Function is missing a return type annotation  [no-untyped-def]
autoto/challonge.py:158: error: Function is missing a return type annotation  [no-untyped-def]
autoto/challonge.py:159: error: Call to untyped function "get_template" in typed context  [no-untyped-call]
autoto/challonge.py:162: error: Function is missing a return type annotation  [no-untyped-def]
autoto/challonge.py:174: error: Function is missing a return type annotation  [no-untyped-def]
autoto/challonge.py:188: error: Need type annotation for 'tournament'  [var-annotated]
autoto/challonge.py:189: error: Need type annotation for 'data'  [var-annotated]
autoto/challonge.py:192: error: Function is missing a return type annotation  [no-untyped-def]
autoto/challonge.py:196: error: Function is missing a return type annotation  [no-untyped-def]
autoto/challonge.py:203: error: Function is missing a return type annotation  [no-untyped-def]
autoto/challonge.py:207: error: Function is missing a return type annotation  [no-untyped-def]
autoto/challonge.py:235: error: Function is missing a return type annotation  [no-untyped-def]
autoto/challonge.py:244: error: Function is missing a return type annotation  [no-untyped-def]
autoto/challonge.py:253: error: Function is missing a return type annotation  [no-untyped-def]
autoto/challonge.py:261: error: Function is missing a return type annotation  [no-untyped-def]
autoto/challonge.py:271: error: Need type annotation for 'data'  [var-annotated]
forum.py:7: error: Skipping analyzing 'urllib3.util.retry': found module but no type hints or library stubs  [import]
forum.py:8: error: Skipping analyzing 'wrapt': found module but no type hints or library stubs  [import]
forum.py:17: error: Function is missing a type annotation  [no-untyped-def]
forum.py:35: error: Function is missing a type annotation  [no-untyped-def]
forum.py:43: error: Call to untyped function "update" in typed context  [no-untyped-call]
forum.py:76: error: Call to untyped function "cookiejar_from_dict" in typed context  [no-untyped-call]
forum.py:83: error: Call to untyped function "items" in typed context  [no-untyped-call]
forum.py:90: error: Function is missing a return type annotation  [no-untyped-def]
forum.py:90: note: Use "-> None" if function does not return a value
forum.py:98: error: Call to untyped function "url" in typed context  [no-untyped-call]
forum.py:105: error: Call to untyped function "url" in typed context  [no-untyped-call]
forum.py:115: error: Call to untyped function "url" in typed context  [no-untyped-call]
forum.py:121: error: Function is missing a type annotation  [no-untyped-def]
forum.py:125: error: Function is missing a type annotation  [no-untyped-def]
forum.py:126: error: Call to untyped function "login" in typed context  [no-untyped-call]
forum.py:129: error: Call to untyped function "url" in typed context  [no-untyped-call]
forum.py:133: error: Function is missing a type annotation  [no-untyped-def]
forum.py:134: error: Call to untyped function "login" in typed context  [no-untyped-call]
forum.py:136: error: Call to untyped function "url" in typed context  [no-untyped-call]
forum.py:138: error: Function is missing a type annotation  [no-untyped-def]
forum.py:139: error: Call to untyped function "login" in typed context  [no-untyped-call]
forum.py:140: error: Call to untyped function "url" in typed context  [no-untyped-call]
forum.py:144: error: Function is missing a type annotation  [no-untyped-def]
forum.py:145: error: Call to untyped function "login" in typed context  [no-untyped-call]
forum.py:157: error: Call to untyped function "url" in typed context  [no-untyped-call]
forum.py:158: error: Incompatible types in assignment (expression has type "float", variable has type "int")  [assignment]
forum.py:161: error: Function is missing a type annotation  [no-untyped-def]
forum.py:162: error: Call to untyped function "login" in typed context  [no-untyped-call]
forum.py:163: error: Call to untyped function "message" in typed context  [no-untyped-call]
forum.py:167: error: Function is missing a type annotation  [no-untyped-def]
forum.py:168: error: Call to untyped function "login" in typed context  [no-untyped-call]
forum.py:187: error: Call to untyped function "url" in typed context  [no-untyped-call]
forum.py:188: error: Incompatible types in assignment (expression has type "float", variable has type "int")  [assignment]
forum.py:191: error: Function is missing a type annotation  [no-untyped-def]
forum.py:192: error: Call to untyped function "login" in typed context  [no-untyped-call]
forum.py:200: error: Call to untyped function "url" in typed context  [no-untyped-call]
auto_to.py:20: error: Skipping analyzing 'challonge': found module but no type hints or library stubs  [import]
auto_to.py:22: error: Skipping analyzing 'click_log': found module but no type hints or library stubs  [import]
auto_to.py:23: error: Skipping analyzing 'dataset': found module but no type hints or library stubs  [import]
auto_to.py:27: error: Skipping analyzing 'lazy': found module but no type hints or library stubs  [import]
auto_to.py:28: error: Skipping analyzing 'mako.template': found module but no type hints or library stubs  [import]
auto_to.py:43: error: Function is missing a type annotation  [no-untyped-def]
auto_to.py:58: error: Call to untyped function "notify" in typed context  [no-untyped-call]
auto_to.py:64: error: Function is missing a type annotation  [no-untyped-def]
auto_to.py:68: error: Function is missing a type annotation  [no-untyped-def]
auto_to.py:107: error: Function is missing a type annotation  [no-untyped-def]
auto_to.py:128: error: Call to untyped function "get_round" in typed context  [no-untyped-call]
auto_to.py:135: error: Call to untyped function "correct_user" in typed context  [no-untyped-call]
auto_to.py:141: error: Call to untyped function "correct_user" in typed context  [no-untyped-call]
auto_to.py:224: error: Call to untyped function "notify" in typed context  [no-untyped-call]
auto_to.py:227: error: Function is missing a type annotation  [no-untyped-def]
auto_to.py:244: error: Function is missing a type annotation  [no-untyped-def]
auto_to.py:256: error: Function is missing a type annotation  [no-untyped-def]
auto_to.py:277: error: Function is missing a type annotation  [no-untyped-def]
auto_to.py:297: error: Function is missing a type annotation  [no-untyped-def]
auto_to.py:298: error: Call to untyped function "setup_notifications" in typed context  [no-untyped-call]
auto_to.py:300: error: Call to untyped function "Forum" in typed context  [no-untyped-call]
auto_to.py:320: error: Function is missing a type annotation  [no-untyped-def]
auto_to.py:328: error: Function is missing a type annotation  [no-untyped-def]
auto_to.py:331: error: Call to untyped function "all_tournaments" in typed context  [no-untyped-call]
auto_to.py:372: error: Call to untyped function "notify" in typed context  [no-untyped-call]
auto_to.py:379: error: Function is missing a type annotation  [no-untyped-def]
auto_to.py:382: error: Call to untyped function "all_tournaments" in typed context  [no-untyped-call]
auto_to.py:424: error: Call to untyped function "notify" in typed context  [no-untyped-call]
auto_to.py:431: error: Function is missing a type annotation  [no-untyped-def]
auto_to.py:432: error: Call to untyped function "all_tournaments" in typed context  [no-untyped-call]
auto_to.py:447: error: Call to untyped function "send_messages" in typed context  [no-untyped-call]
auto_to.py:456: error: Function is missing a type annotation  [no-untyped-def]
auto_to.py:457: error: Call to untyped function "all_tournaments" in typed context  [no-untyped-call]
auto_to.py:474: error: Call to untyped function "send_messages" in typed context  [no-untyped-call]
auto_to.py:483: error: Function is missing a type annotation  [no-untyped-def]
auto_to.py:484: error: Call to untyped function "all_tournaments" in typed context  [no-untyped-call]
auto_to.py:492: error: Function is missing a return type annotation  [no-untyped-def]
auto_to.py:492: note: Use "-> None" if function does not return a value
auto_to.py:500: error: Function is missing a type annotation  [no-untyped-def]
auto_to.py:520: error: Function is missing a type annotation  [no-untyped-def]
auto_to.py:582: error: Function is missing a type annotation  [no-untyped-def]
auto_to.py:593: error: Function is missing a type annotation  [no-untyped-def]
auto_to.py:610: error: Function is missing a type annotation  [no-untyped-def]
auto_to.py:615: error: Function is missing a type annotation  [no-untyped-def]
auto_to.py:620: error: Function is missing a type annotation  [no-untyped-def]
auto_to.py:625: error: Function is missing a type annotation  [no-untyped-def]
auto_to.py:631: error: Function is missing a type annotation  [no-untyped-def]
auto_to.py:634: error: Function is missing a return type annotation  [no-untyped-def]
auto_to.py:640: error: Function is missing a type annotation  [no-untyped-def]
auto_to.py:645: error: Call to untyped function "from_stars" of "League" in typed context  [no-untyped-call]
auto_to.py:646: error: Call to untyped function "from_stars" of "League" in typed context  [no-untyped-call]
auto_to.py:672: error: Function is missing a type annotation  [no-untyped-def]
auto_to.py:682: error: Call to untyped function "match_cost" in typed context  [no-untyped-call]
auto_to.py:692: error: Function is missing a type annotation  [no-untyped-def]
auto_to.py:700: error: Function is missing a type annotation  [no-untyped-def]
auto_to.py:722: error: Call to untyped function "greedy_matches" in typed context  [no-untyped-call]
auto_to.py:727: error: Call to untyped function "get_template" in typed context  [no-untyped-call]
auto_to.py:728: error: Call to untyped function "send_messages" in typed context  [no-untyped-call]
auto_to.py:734: error: Call to untyped function "ranked_match_id" in typed context  [no-untyped-call]
auto_to.py:753: error: Function is missing a type annotation  [no-untyped-def]
auto_to.py:754: error: Call to untyped function "get_template" in typed context  [no-untyped-call]
auto_to.py:755: error: Call to untyped function "send_messages" in typed context  [no-untyped-call]
auto_to.py:761: error: Call to untyped function "ranked_match_id" in typed context  [no-untyped-call]
auto_to.py:774: error: Function is missing a type annotation  [no-untyped-def]
auto_to.py:780: error: Function is missing a return type annotation  [no-untyped-def]
auto_to.py:784: error: Function is missing a return type annotation  [no-untyped-def]
auto_to.py:788: error: Function is missing a type annotation  [no-untyped-def]
auto_to.py:792: error: Function is missing a type annotation  [no-untyped-def]
auto_to.py:793: error: Call to untyped function "Box" in typed context  [no-untyped-call]
auto_to.py:795: error: Function is missing a type annotation  [no-untyped-def]
auto_to.py:810: error: Call to untyped function "Box" in typed context  [no-untyped-call]
auto_to.py:817: error: Function is missing a return type annotation  [no-untyped-def]
auto_to.py:822: error: Function is missing a type annotation  [no-untyped-def]
auto_to.py:826: error: Function is missing a return type annotation  [no-untyped-def]
auto_to.py:830: error: Function is missing a return type annotation  [no-untyped-def]
auto_to.py:834: error: Function is missing a return type annotation  [no-untyped-def]
auto_to.py:837: error: Function is missing a type annotation  [no-untyped-def]
auto_to.py:840: error: Function is missing a return type annotation  [no-untyped-def]
auto_to.py:845: error: Function is missing a type annotation  [no-untyped-def]
auto_to.py:849: error: Call to untyped function "SingletonBracket" in typed context  [no-untyped-call]
auto_to.py:854: error: Call to untyped function "SingletonBracket" in typed context  [no-untyped-call]
auto_to.py:881: error: Function is missing a return type annotation  [no-untyped-def]
auto_to.py:885: error: Function is missing a return type annotation  [no-untyped-def]
auto_to.py:889: error: Function is missing a return type annotation  [no-untyped-def]
auto_to.py:892: error: Function is missing a type annotation  [no-untyped-def]
auto_to.py:893: error: Call to untyped function "Box" in typed context  [no-untyped-call]
auto_to.py:893: error: Call to untyped function "render" in typed context  [no-untyped-call]
auto_to.py:895: error: Function is missing a type annotation  [no-untyped-def]
auto_to.py:896: error: Call to untyped function "Box" in typed context  [no-untyped-call]
auto_to.py:896: error: Call to untyped function "render" in typed context  [no-untyped-call]
auto_to.py:898: error: Function is missing a type annotation  [no-untyped-def]
auto_to.py:899: error: Call to untyped function "top_box" in typed context  [no-untyped-call]
auto_to.py:900: error: Call to untyped function "bottom_box" in typed context  [no-untyped-call]
auto_to.py:903: error: Call to untyped function "Box" in typed context  [no-untyped-call]
auto_to.py:909: error: Call to untyped function "Box" in typed context  [no-untyped-call]
auto_to.py:915: error: Call to untyped function "empty" of "Box" in typed context  [no-untyped-call]
auto_to.py:922: error: Call to untyped function "Box" in typed context  [no-untyped-call]
auto_to.py:933: error: Call to untyped function "vertical" of "Box" in typed context  [no-untyped-call]
auto_to.py:938: error: Function is missing a return type annotation  [no-untyped-def]
auto_to.py:939: error: Call to untyped function "render" in typed context  [no-untyped-call]
auto_to.py:942: error: Function is missing a type annotation  [no-untyped-def]
auto_to.py:976: error: Call to untyped function "bracket_history" in typed context  [no-untyped-call]
auto_to.py:1003: error: Call to untyped function "bracket_history" in typed context  [no-untyped-call]
auto_to.py:1009: error: Call to untyped function "Bracket" in typed context  [no-untyped-call]
auto_to.py:1015: error: Function is missing a type annotation  [no-untyped-def]
auto_to.py:1030: error: Function is missing a type annotation  [no-untyped-def]
auto_to.py:1048: error: Function is missing a type annotation  [no-untyped-def]
auto_to.py:1113: error: Function is missing a type annotation  [no-untyped-def]
auto_to.py:1141: error: Function is missing a type annotation  [no-untyped-def]
auto_to.py:1152: error: Function is missing a type annotation  [no-untyped-def]
auto_to.py:1154: error: Call to untyped function "from_stars" of "League" in typed context  [no-untyped-call]
auto_to.py:1171: error: Call to untyped function "append_player_rankings" in typed context  [no-untyped-call]
auto_to.py:1175: error: Call to untyped function "append_player_rankings" in typed context  [no-untyped-call]
auto_to.py:1184: error: Call to untyped function "bracket_history" in typed context  [no-untyped-call]
auto_to.py:1191: error: Function is missing a type annotation  [no-untyped-def]
auto_to.py:1206: error: Function is missing a type annotation  [no-untyped-def]
auto_to.py:1232: error: Function is missing a type annotation  [no-untyped-def]
auto_to.py:1233: error: Function is missing a type annotation  [no-untyped-def]
auto_to.py:1242: error: Call to untyped function "autoto_command" in typed context  [no-untyped-call]
auto_to.py:1243: error: Function is missing a type annotation  [no-untyped-def]
auto_to.py:1287: error: Call to untyped function "Calendar" in typed context  [no-untyped-call]
auto_to.py:1287: error: Call to untyped function "insert_event" in typed context  [no-untyped-call]
auto_to.py:1303: error: Call to untyped function "Calendar" in typed context  [no-untyped-call]
auto_to.py:1303: error: Call to untyped function "update_event" in typed context  [no-untyped-call]
auto_to.py:1331: error: Call to untyped function "notify" in typed context  [no-untyped-call]
auto_to.py:1334: error: Call to untyped function "autoto_command" in typed context  [no-untyped-call]
auto_to.py:1338: error: Function is missing a type annotation  [no-untyped-def]
auto_to.py:1350: error: Function is missing a type annotation  [no-untyped-def]
auto_to.py:1372: error: Function is missing a type annotation  [no-untyped-def]
auto_to.py:1383: error: Function is missing a type annotation  [no-untyped-def]
auto_to.py:1402: error: Call to untyped function "merge_by_date" in typed context  [no-untyped-call]
auto_to.py:1447: error: Function is missing a type annotation  [no-untyped-def]
auto_to.py:1466: error: Item "None" of "Optional[datetime]" has no attribute "astimezone"  [union-attr]
auto_to.py:1469: error: Function is missing a type annotation  [no-untyped-def]
auto_to.py:1492: error: Function is missing a type annotation  [no-untyped-def]
Found 230 errors in 7 files (checked 8 source files)

***
Strict run completed and uncovered 230 mypy errors. Building the strictest mypy config such that all configured mypy checks still pass...

WARNING: mypy was not able to find type hints for module 'notify2' since it does not seem to be installed in the current environment. Assuming it has no type hints available.
> Mypy was unable to find type hints for some 3rd party modules, configuring mypy to ignore them.
    More info: https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports
    Affected modules: ['apiclient', 'challonge', 'click_log', 'dataset', 'httplib2', 'lazy', 'mako.template', 'notify2', 'oauth2client', 'setuptools', 'urllib3.util.retry', 'wrapt']

> Constructed 18 mypy error suppression rules across 6 modules.

Config generated (84 lines). Verifying the last few mypy settings and validating that the new configuration does not produce mypy errors. Please wait...

Writing temporary mypy config file:


# Autogenerated by typing_copilot v0.5.4
[mypy]
no_implicit_optional = True
strict_optional = True
warn_redundant_casts = True
check_untyped_defs = True
disallow_untyped_calls = True
disallow_incomplete_defs = True
disallow_untyped_defs = True
disallow_untyped_decorators = True
ignore_missing_imports = False
warn_unused_ignores = True


# First party per-module rule relaxations
[mypy-auto_to.*]
check_untyped_defs = False
disallow_incomplete_defs = False
disallow_untyped_calls = False
disallow_untyped_defs = False

[mypy-autoto.*]
disallow_untyped_calls = False
disallow_untyped_defs = False

[mypy-autoto.challonge.*]
check_untyped_defs = False
disallow_incomplete_defs = False

[mypy-forum.*]
check_untyped_defs = False
disallow_incomplete_defs = False
disallow_untyped_calls = False
disallow_untyped_defs = False

[mypy-gcal.*]
check_untyped_defs = False
disallow_incomplete_defs = False
disallow_untyped_calls = False
disallow_untyped_defs = False

[mypy-notify.*]
disallow_incomplete_defs = False
disallow_untyped_defs = False


# Third-party module rule relaxations
[mypy-apiclient.*]
ignore_missing_imports = True

[mypy-challonge.*]
ignore_missing_imports = True

[mypy-click_log.*]
ignore_missing_imports = True

[mypy-dataset.*]
ignore_missing_imports = True

[mypy-httplib2.*]
ignore_missing_imports = True

[mypy-lazy.*]
ignore_missing_imports = True

[mypy-mako.template.*]
ignore_missing_imports = True

[mypy-notify2.*]
ignore_missing_imports = True

[mypy-oauth2client.*]
ignore_missing_imports = True

[mypy-setuptools.*]
ignore_missing_imports = True

[mypy-urllib3.util.retry.*]
ignore_missing_imports = True

[mypy-wrapt.*]
ignore_missing_imports = True


Running mypy with ['mypy', '--config-file', '/tmp/mypy-copilot-17jzpequ/mypy.ini', '--show-error-codes', '--error-summary', '.']
Run completed with exit code 1. Stdout: ***
auto_to.py:1466: error: Item "None" of "Optional[datetime]" has no attribute "astimezone"  [union-attr]
Found 1 error in 1 file (checked 8 source files)

***
Validation failed due to unexpected error(s):
[MypyError(file_path='auto_to.py', line_number=1466, error_code='union-attr', message='error: Item "None" of "Optional[datetime]" has no attribute "astimezone"')]
Traceback (most recent call last):
  File "/home/cpennington/.virtualenvs/yomi-auto-to/bin/typing_copilot", line 8, in <module>
    sys.exit(cli())
  File "/home/cpennington/.virtualenvs/yomi-auto-to/lib/python3.9/site-packages/click/core.py", line 829, in __call__
    return self.main(*args, **kwargs)
  File "/home/cpennington/.virtualenvs/yomi-auto-to/lib/python3.9/site-packages/click/core.py", line 782, in main
    rv = self.invoke(ctx)
  File "/home/cpennington/.virtualenvs/yomi-auto-to/lib/python3.9/site-packages/click/core.py", line 1259, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/cpennington/.virtualenvs/yomi-auto-to/lib/python3.9/site-packages/click/core.py", line 1066, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/cpennington/.virtualenvs/yomi-auto-to/lib/python3.9/site-packages/click/core.py", line 610, in invoke
    return callback(*args, **kwargs)
  File "/home/cpennington/.virtualenvs/yomi-auto-to/lib/python3.9/site-packages/typing_copilot/cli.py", line 254, in init
    unused_ignore_errors = _get_unused_ignore_errors_from_validation_run(final_config)
  File "/home/cpennington/.virtualenvs/yomi-auto-to/lib/python3.9/site-packages/typing_copilot/cli.py", line 136, in _get_unused_ignore_errors_from_validation_run
    raise AssertionError(
AssertionError: Validation failed: mypy reported 1 unexpected error(s). Please submit the produced logs so we can update typing-copilot to fix this issue.Apologies for the inconvenience, and thank you for supporting typing-copilot.```

cpennington avatar Feb 15 '21 19:02 cpennington

Ah excellent, thank you! I can see from the verbose log that mypy in the strict run did report the issue, so this is purely a typing_copilot failure to generate an appropriate config file. Should be a relatively easy fix.

Thanks for the help tracking down the bug!

obi1kenobi avatar Feb 15 '21 20:02 obi1kenobi

After further investigation, this is a sibling of #4 -- same underlying cause, just affecting a different error code. Unfortunately, this setting is not possible to override on a per-file basis, and since it catches real bugs (like the one in this case), I think it's inappropriate to suppress project-wide.

The best thing we can do is improve the error message to inform the user of the issue earlier in the process, and perhaps support an "I know what I'm doing" option to disable the error check globally, as a measure of last resort available to well-informed users. Related: https://github.com/obi1kenobi/typing_copilot/issues/4#issuecomment-880889814

obi1kenobi avatar Jul 15 '21 17:07 obi1kenobi