Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
satella
Manage
Activity
Members
Labels
Plan
Issues
1
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
public
satella
Commits
0c12da2b
Commit
0c12da2b
authored
4 years ago
by
Piotr Maślanka
Browse files
Options
Downloads
Patches
Plain Diff
2.11.33 bugfix
parent
facb0e12
No related branches found
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
CHANGELOG.md
+2
-0
2 additions, 0 deletions
CHANGELOG.md
satella/__init__.py
+1
-1
1 addition, 1 deletion
satella/__init__.py
satella/coding/misc.py
+25
-14
25 additions, 14 deletions
satella/coding/misc.py
tests/test_coding/test_debug.py
+39
-3
39 additions, 3 deletions
tests/test_coding/test_debug.py
with
67 additions
and
18 deletions
CHANGELOG.md
+
2
−
0
View file @
0c12da2b
# v2.11.33
*
bugfix release: a fix for a certain bug involving
`get_arguments`
and
`classmethod`
This diff is collapsed.
Click to expand it.
satella/__init__.py
+
1
−
1
View file @
0c12da2b
__version__
=
'
2.11.33
_a1
'
__version__
=
'
2.11.33
'
This diff is collapsed.
Click to expand it.
satella/coding/misc.py
+
25
−
14
View file @
0c12da2b
...
...
@@ -104,6 +104,9 @@ def get_arguments(function: tp.Callable, *args, **kwargs) -> \
Return local variables that would be defined for given function if called with
provided arguments.
Note that this function will not return the
"
self
"
argument of methods
and it won
'
t return the class of
"
cls
"
of classmethods.
:param function: callable to examine
:param args: arguments to provide
:param kwargs: keyword arguments to provide
...
...
@@ -129,36 +132,36 @@ def _get_arguments(function: tp.Callable, special_behaviour: bool, *args, **kwar
Parameter
.
VAR_POSITIONAL
)]
args
=
list
(
reversed
(
args
))
p
ar
ams_taken
=
set
(
)
while
len
(
positionals
)
>
0
:
ar
guments_left
=
set
(
param
.
name
for
param
in
params
)
while
len
(
positionals
):
arg
=
positionals
.
pop
()
if
arg
.
kind
==
Parameter
.
VAR_POSITIONAL
and
not
special_behaviour
:
local_vars
[
arg
.
name
]
=
tuple
(
reversed
(
args
))
arg_kind
=
arg
.
kind
arg_name
=
arg
.
name
if
arg_kind
==
Parameter
.
VAR_POSITIONAL
and
not
special_behaviour
:
local_vars
[
arg_name
]
=
tuple
(
reversed
(
args
))
else
:
try
:
v
=
args
.
pop
()
arguments_left
.
remove
(
arg_name
)
except
IndexError
:
if
arg
.
default
==
Parameter
.
empty
:
if
special_behaviour
:
v
=
None
else
:
raise
TypeError
(
'
Not enough arguments
'
)
break
else
:
v
=
arg
.
default
local_vars
[
arg
.
name
]
=
v
params_taken
.
add
(
arg
.
name
)
local_vars
[
arg_name
]
=
v
keywords
=
[
param
for
param
in
params
if
param
.
kind
in
(
Parameter
.
POSITIONAL_OR_KEYWORD
,
Parameter
.
KEYWORD_ONLY
,
Parameter
.
VAR_KEYWORD
)
and
param
.
name
not
in
p
ar
ams_taken
]
and
param
.
name
in
ar
guments_left
]
for
keyword
in
keywords
:
keyword_name
=
keyword
.
name
if
keyword
.
kind
==
Parameter
.
VAR_KEYWORD
and
not
special_behaviour
:
local_vars
[
keyword
.
name
]
=
kwargs
local_vars
[
keyword
_
name
]
=
kwargs
else
:
try
:
v
=
kwargs
.
pop
(
keyword
.
name
)
v
=
kwargs
.
pop
(
keyword
_
name
)
except
KeyError
:
if
keyword
.
default
==
Parameter
.
empty
:
if
special_behaviour
:
...
...
@@ -168,7 +171,15 @@ def _get_arguments(function: tp.Callable, special_behaviour: bool, *args, **kwar
else
:
v
=
keyword
.
default
local_vars
[
keyword
.
name
]
=
v
local_vars
[
keyword_name
]
=
v
for
param
in
params
:
param_name
=
param
.
name
if
param_name
not
in
local_vars
:
if
special_behaviour
:
local_vars
[
param_name
]
=
None
else
:
raise
TypeError
(
'
Not enough keyword arguments
'
)
return
local_vars
...
...
This diff is collapsed.
Click to expand it.
tests/test_coding/test_debug.py
+
39
−
3
View file @
0c12da2b
import
unittest
from
satella.coding
import
precondition
,
short_none
,
has_keys
,
update_if_not_none
,
postcondition
from
satella.coding
import
precondition
,
short_none
,
has_keys
,
update_if_not_none
,
postcondition
,
\
get_arguments
from
satella.coding.decorators
import
for_argument
from
satella.exceptions
import
PreconditionError
class
TestTypecheck
(
unittest
.
TestCase
):
def
test_get_arguments_bug
(
self
):
class
Class
:
@classmethod
def
execute
(
cls
,
password
:
str
,
service
:
str
,
absolute_expiration
=
None
,
metadata
=
None
):
pass
def
method_call
(
self
,
password
:
str
,
service
:
str
,
absolute_expiration
=
None
,
metadata
=
None
):
pass
kls
=
Class
()
args
=
get_arguments
(
Class
.
execute
,
'
1234
'
,
'
service
'
,
metadata
=
{
'
ok
'
:
'
meta
'
})
self
.
assertEqual
(
args
,
{
'
password
'
:
'
1234
'
,
'
service
'
:
'
service
'
,
'
metadata
'
:
{
'
ok
'
:
'
meta
'
},
'
absolute_expiration
'
:
None
})
args
=
get_arguments
(
kls
.
method_call
,
'
1234
'
,
'
service
'
,
metadata
=
{
'
ok
'
:
'
meta
'
})
self
.
assertEqual
(
args
,
{
'
password
'
:
'
1234
'
,
'
service
'
:
'
service
'
,
'
metadata
'
:
{
'
ok
'
:
'
meta
'
},
'
absolute_expiration
'
:
None
})
self
.
assertRaises
(
TypeError
,
lambda
:
get_arguments
(
kls
.
method_call
,
'
1234
'
))
self
.
assertRaises
(
TypeError
,
lambda
:
get_arguments
(
Class
.
execute
,
'
1234
'
))
def
test_for_argument_extended
(
self
):
@for_argument
(
int
)
def
accept_default
(
a
=
5
):
def
accept_default
(
a
=
'
5
'
):
return
a
self
.
assertEqual
(
accept_default
(
6
),
6
)
self
.
assertEqual
(
accept_default
(
'
6
'
),
6
)
self
.
assertEqual
(
accept_default
(),
5
)
def
test_for_argument_str
(
self
):
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment