Skip to content

Commit

Permalink
Add typing module extension
Browse files Browse the repository at this point in the history
  • Loading branch information
cdce8p committed Feb 27, 2021
1 parent 3ef6aa6 commit de223ec
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions astroid/brain/brain_typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"""Astroid hooks for typing.py support."""
import typing

import astroid
from astroid import (
MANAGER,
UseInferenceDefault,
Expand Down Expand Up @@ -85,6 +86,24 @@ def infer_typing_attr(node, context=None):
return node.infer(context=context)


def typing_module_extension():
return astroid.parse(
"""
class Hashable:
__slots__ = ()
@abstractmethod
def __hash__(self) -> int:
return 0
class Sized:
__slots__ = ()
@abstracmethod
def __len__(self) -> int:
return 0
"""
)


MANAGER.register_transform(
nodes.Call,
inference_tip(infer_typing_typevar_or_newtype),
Expand All @@ -93,3 +112,5 @@ def infer_typing_attr(node, context=None):
MANAGER.register_transform(
nodes.Subscript, inference_tip(infer_typing_attr), _looks_like_typing_subscript
)

astroid.register_module_extender(MANAGER, "typing", typing_module_extension)

0 comments on commit de223ec

Please sign in to comment.