-
-
Notifications
You must be signed in to change notification settings - Fork 485
New semanal-progress rebased on master #445
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
kszmigiel
wants to merge
76
commits into
typeddjango:master
Choose a base branch
from
kszmigiel:feature/plugin_cleanup
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,527
−1,169
Open
Changes from all commits
Commits
Show all changes
76 commits
Select commit
Hold shift + click to select a range
77daf90
refactor, fix method copying
mkurnikov db925ac
QuerySet.as_manager() support
mkurnikov 74ccc4d
allow manager classes nested inside model classes
mkurnikov f58cbea
lint fixes
mkurnikov 4bf5ec9
fix tests
mkurnikov 585273a
add two new as_manager tests
mkurnikov c0f41f3
wip
mkurnikov e9bdc50
wip
mkurnikov b51ec9d
remove as_manager support
mkurnikov 7d004ff
remove generics support for tests
mkurnikov 13cec79
remove as_manager/from_queryset leftovers and fix tests
mkurnikov c8641fb
remove files
mkurnikov 05e0f40
rebase
mkurnikov 4749d15
proper rebase
mkurnikov 59ff90e
FormCallback
mkurnikov 5093939
get_user_model support for new callbacks api
mkurnikov c0e5c46
lints
mkurnikov 56515da
isort
mkurnikov bf48ef2
remove one more irrelevant file
mkurnikov 196179b
disable test suites checking in CI
mkurnikov 59ce2ed
remove transformers/models
mkurnikov b4d8df1
more changes to new API
mkurnikov 774c14f
remove unused import
mkurnikov 4af54e7
remove some dead code
mkurnikov cca106d
lints
mkurnikov bd325e0
replace field callback with new API
mkurnikov fc60ceb
move meta to new API
mkurnikov 57ee7c9
move orm_lookups to new API
mkurnikov 43f488b
move init_create to new API
mkurnikov 6debf6d
move querysets to new API
mkurnikov 9e0f438
transformers2 -> transformers
mkurnikov d67a117
remove a bunch of dead code
mkurnikov a9fa3c0
add callback class for from_queryset()
04345bb
helpers
3b3f5e1
typos
c731711
method for copying methods
627fe61
cleanp after 1st CR
040c0d9
cleanup after 2nd CR, exceptions instead of returns
86ed790
fallback to Any if can not resolve from_queryset Manager
e8f1f19
implemented AddManagers.run_with_model_cls() from master
c3ee1a5
tests for from_queryset
deee98c
remove print
0c8735f
flak8 cleanup
707569b
reverted to old way of creating typeinfo, probably refactor needed on…
78aa41f
fix 2 of failing tests
2b75646
fix 3rd test
5a1aff7
fix the last test
0890d29
isort
3d1014a
fix first mypy plugin code error
e6cef08
another try to fix mypy for plugin code errors
f64932d
fix isort
818db9b
added type ignore comments in places where mypy doesnt resolve type c…
3a0c9a4
flake8
f048a28
error message formatted properly
8390de3
unused type ignore comment
e6d91ef
use of cast instead of type ignore
19b6eb6
fix issue #438 manager method is forward reference
51b021f
typo in test
c5f4256
fixed condition for defering
50fe47a
assert instead of return
3cad5e3
uncommented tests
kszmigiel 20ef55e
isort
kszmigiel 61a330c
fix test (note assertion on HttpRequest.user)
kszmigiel ab07ffc
isort and test revert
kszmigiel 1ae0d85
fix for bound_arg_type
kszmigiel c54eced
django typecheck fix (?)
kszmigiel 9b42185
fix typecheck test suite WIP
kszmigiel d92ea39
WIP django test suite bugfixing
kszmigiel 998cc56
remove comment to check tests
kszmigiel 125aa64
fix running tests, flak8
kszmigiel 6691967
add ignore error
kszmigiel 4d051e3
SmallAutoField stub
kszmigiel b4bf1d4
MemberExpr NameExpr return default
kszmigiel 6d034bd
fix error_context type
kszmigiel 4c3e588
add error ignore for test model inharitence
kszmigiel da09a4c
ignore error in test_abstract_inheritance
kszmigiel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
from typing import Dict, List, Optional, Set, Union | ||
|
||
from mypy import checker | ||
from mypy.checker import TypeChecker | ||
from mypy.mro import calculate_mro | ||
from mypy.nodes import ( | ||
GDEF, MDEF, Block, ClassDef, Expression, MypyFile, SymbolTable, SymbolTableNode, TypeInfo, Var, | ||
) | ||
from mypy.plugin import ( | ||
AttributeContext, CheckerPluginInterface, FunctionContext, MethodContext, | ||
) | ||
from mypy.types import AnyType, Instance, TupleType | ||
from mypy.types import Type as MypyType | ||
from mypy.types import TypedDictType, TypeOfAny | ||
|
||
from mypy_django_plugin.lib import helpers | ||
|
||
|
||
def add_new_class_for_current_module(current_module: MypyFile, | ||
name: str, | ||
bases: List[Instance], | ||
fields: Optional[Dict[str, MypyType]] = None | ||
) -> TypeInfo: | ||
new_class_unique_name = checker.gen_unique_name(name, current_module.names) | ||
|
||
# make new class expression | ||
classdef = ClassDef(new_class_unique_name, Block([])) | ||
classdef.fullname = current_module.fullname + '.' + new_class_unique_name | ||
|
||
# make new TypeInfo | ||
new_typeinfo = TypeInfo(SymbolTable(), classdef, current_module.fullname) | ||
new_typeinfo.bases = bases | ||
calculate_mro(new_typeinfo) | ||
new_typeinfo.calculate_metaclass_type() | ||
|
||
# add fields | ||
if fields: | ||
for field_name, field_type in fields.items(): | ||
var = Var(field_name, type=field_type) | ||
var.info = new_typeinfo | ||
var._fullname = new_typeinfo.fullname + '.' + field_name | ||
new_typeinfo.names[field_name] = SymbolTableNode(MDEF, var, plugin_generated=True) | ||
|
||
classdef.info = new_typeinfo | ||
current_module.names[new_class_unique_name] = SymbolTableNode(GDEF, new_typeinfo, plugin_generated=True) | ||
return new_typeinfo | ||
|
||
|
||
def make_oneoff_named_tuple(api: TypeChecker, name: str, fields: 'Dict[str, MypyType]') -> TupleType: | ||
current_module = helpers.get_current_module(api) | ||
namedtuple_info = add_new_class_for_current_module(current_module, name, | ||
bases=[api.named_generic_type('typing.NamedTuple', [])], | ||
fields=fields) | ||
return TupleType(list(fields.values()), fallback=Instance(namedtuple_info, [])) | ||
|
||
|
||
def make_tuple(api: 'TypeChecker', fields: List[MypyType]) -> TupleType: | ||
# fallback for tuples is any builtins.tuple instance | ||
fallback = api.named_generic_type('builtins.tuple', | ||
[AnyType(TypeOfAny.special_form)]) | ||
return TupleType(fields, fallback=fallback) | ||
|
||
|
||
def make_oneoff_typeddict(api: CheckerPluginInterface, fields: 'Dict[str, MypyType]', | ||
required_keys: Set[str]) -> TypedDictType: | ||
object_type = api.named_generic_type('mypy_extensions._TypedDict', []) | ||
typed_dict_type = TypedDictType(fields, # type: ignore | ||
required_keys=required_keys, | ||
fallback=object_type) | ||
return typed_dict_type | ||
|
||
|
||
def get_typechecker_api(ctx: Union[AttributeContext, MethodContext, FunctionContext]) -> TypeChecker: | ||
if not isinstance(ctx.api, TypeChecker): | ||
raise ValueError('Not a TypeChecker') | ||
return ctx.api | ||
|
||
|
||
def check_types_compatible(ctx: Union[FunctionContext, MethodContext], | ||
*, expected_type: MypyType, actual_type: MypyType, error_message: str) -> None: | ||
api = get_typechecker_api(ctx) | ||
api.check_subtype(actual_type, expected_type, | ||
ctx.context, error_message, | ||
'got', 'expected') | ||
|
||
|
||
def get_call_argument_by_name(ctx: Union[FunctionContext, MethodContext], name: str) -> Optional[Expression]: | ||
""" | ||
Return the expression for the specific argument. | ||
This helper should only be used with non-star arguments. | ||
""" | ||
if name not in ctx.callee_arg_names: | ||
return None | ||
idx = ctx.callee_arg_names.index(name) | ||
args = ctx.args[idx] | ||
if len(args) != 1: | ||
# Either an error or no value passed. | ||
return None | ||
return args[0] | ||
|
||
|
||
def get_call_argument_type_by_name(ctx: Union[FunctionContext, MethodContext], name: str) -> Optional[MypyType]: | ||
"""Return the type for the specific argument. | ||
This helper should only be used with non-star arguments. | ||
""" | ||
if name not in ctx.callee_arg_names: | ||
return None | ||
idx = ctx.callee_arg_names.index(name) | ||
arg_types = ctx.arg_types[idx] | ||
if len(arg_types) != 1: | ||
# Either an error or no value passed. | ||
return None | ||
return arg_types[0] | ||
|
||
|
||
def add_new_sym_for_info(info: TypeInfo, *, name: str, sym_type: MypyType) -> None: | ||
# type=: type of the variable itself | ||
var = Var(name=name, type=sym_type) | ||
# var.info: type of the object variable is bound to | ||
var.info = info | ||
var._fullname = info.fullname + '.' + name | ||
var.is_initialized_in_class = True | ||
var.is_inferred = True | ||
info.names[name] = SymbolTableNode(MDEF, var, | ||
plugin_generated=True) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
def make_classes_generic(*klasses: type) -> None: | ||
for klass in klasses: | ||
def fake_classgetitem(cls, *args, **kwargs): | ||
return cls | ||
|
||
klass.__class_getitem__ = classmethod(fake_classgetitem) # type: ignore |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will only affect
django>=3.1
We do need legacy support.