mirror of
https://github.com/status-im/PyGithub.git
synced 2026-08-31 10:51:14 +00:00
Use a special value for not set attributes and parameters
This commit is contained in:
@@ -6,27 +6,27 @@
|
||||
|
||||
def _initAttributes( self ):
|
||||
{% for attribute in class.attributes|dictsort:"name" %}
|
||||
self._{{ attribute.name }} = None
|
||||
self._{{ attribute.name }} = GithubObject.NotSet
|
||||
{% endfor %}
|
||||
|
||||
def _useAttributes( self, attributes ):
|
||||
{% for attribute in class.attributes|dictsort:"name" %}
|
||||
if "{{ attribute.name }}" in attributes and attributes[ "{{ attribute.name }}" ] is not None: # pragma no branch
|
||||
if "{{ attribute.name }}" in attributes: # pragma no branch
|
||||
|
||||
{% if attribute.type.cardinality == "scalar" %}
|
||||
|
||||
{% if attribute.type.simple %}
|
||||
{% if attribute.type.name == "string" %}
|
||||
assert isinstance( attributes[ "{{ attribute.name }}" ], ( str, unicode ) ), attributes[ "{{ attribute.name }}" ]
|
||||
assert attributes[ "{{ attribute.name }}" ] is None or isinstance( attributes[ "{{ attribute.name }}" ], ( str, unicode ) ), attributes[ "{{ attribute.name }}" ]
|
||||
{% endif %}
|
||||
{% if attribute.type.name == "integer" %}
|
||||
assert isinstance( attributes[ "{{ attribute.name }}" ], int ), attributes[ "{{ attribute.name }}" ]
|
||||
assert attributes[ "{{ attribute.name }}" ] is None or isinstance( attributes[ "{{ attribute.name }}" ], int ), attributes[ "{{ attribute.name }}" ]
|
||||
{% endif %}
|
||||
{% if attribute.type.name == "bool" %}
|
||||
assert isinstance( attributes[ "{{ attribute.name }}" ], bool ), attributes[ "{{ attribute.name }}" ]
|
||||
assert attributes[ "{{ attribute.name }}" ] is None or isinstance( attributes[ "{{ attribute.name }}" ], bool ), attributes[ "{{ attribute.name }}" ]
|
||||
{% endif %}
|
||||
{% else %}
|
||||
assert isinstance( attributes[ "{{ attribute.name }}" ], dict ), attributes[ "{{ attribute.name }}" ]
|
||||
assert attributes[ "{{ attribute.name }}" ] is None or isinstance( attributes[ "{{ attribute.name }}" ], dict ), attributes[ "{{ attribute.name }}" ]
|
||||
{% endif %}
|
||||
|
||||
{% else %}
|
||||
@@ -52,7 +52,7 @@
|
||||
{% if attribute.type.simple %}
|
||||
self._{{ attribute.name }} = attributes[ "{{ attribute.name }}" ]
|
||||
{% else %}
|
||||
self._{{ attribute.name }} = {% if attribute.type.name != class.name %}{{ attribute.type.name }}.{% endif %}{{ attribute.type.name }}( self._requester, attributes[ "{{ attribute.name }}" ], completed = False )
|
||||
self._{{ attribute.name }} = None if attributes[ "{{ attribute.name }}" ] is None else {% if attribute.type.name != class.name %}{{ attribute.type.name }}.{% endif %}{{ attribute.type.name }}( self._requester, attributes[ "{{ attribute.name }}" ], completed = False )
|
||||
{% endif %}
|
||||
|
||||
{% else %}
|
||||
|
||||
@@ -35,7 +35,7 @@
|
||||
{% endfor %}
|
||||
{% for parameter in method.optionalParameters %}
|
||||
{% if parameter.type.name != "@todo" %}
|
||||
if {{ parameter.name }} is not DefaultValueForOptionalParameters:
|
||||
if {{ parameter.name }} is not GithubObject.NotSet:
|
||||
{% endif %}
|
||||
|
||||
{% if parameter.type.cardinality == "scalar" %}
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
post_parameters = dict()
|
||||
{% endif %}
|
||||
{% for parameter in method.optionalParameters %}
|
||||
if {{ parameter.name }} is not DefaultValueForOptionalParameters:
|
||||
if {{ parameter.name }} is not GithubObject.NotSet:
|
||||
post_parameters[ "{{ parameter.name }}" ] = {{ parameter.name }}
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
@@ -24,7 +24,7 @@
|
||||
{% if method.optionalParameters %}
|
||||
url_parameters = dict()
|
||||
{% for parameter in method.optionalParameters %}
|
||||
if {{ parameter.name }} is not DefaultValueForOptionalParameters:
|
||||
if {{ parameter.name }} is not GithubObject.NotSet:
|
||||
url_parameters[ "{{ parameter.name }}" ] = {{ parameter.name }}
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
|
||||
@@ -1 +1 @@
|
||||
self{% for parameter in function.mandatoryParameters %}, {{ parameter.name }}{% endfor %}{% for parameter in function.optionalParameters %}, {{ parameter.name }} = DefaultValueForOptionalParameters{% endfor %}{% if function.variadicParameter %}, *{{ function.variadicParameter.name }}s{% endif %}
|
||||
self{% for parameter in function.mandatoryParameters %}, {{ parameter.name }}{% endfor %}{% for parameter in function.optionalParameters %}, {{ parameter.name }} = GithubObject.NotSet{% endfor %}{% if function.variadicParameter %}, *{{ function.variadicParameter.name }}s{% endif %}
|
||||
@@ -2,7 +2,7 @@
|
||||
@property
|
||||
def {{ attribute.name }}( self ):
|
||||
{% if class.isCompletable %}
|
||||
self._completeIfNeeded( self._{{ attribute.name }} )
|
||||
self._completeIfNotSet( self._{{ attribute.name }} )
|
||||
{% endif %}
|
||||
return self._{{ attribute.name }}
|
||||
return self._NoneIfNotSet( self._{{ attribute.name }} )
|
||||
{% endfor %}
|
||||
|
||||
@@ -7,9 +7,6 @@ import GithubObject
|
||||
{% if class.needsPaginatedList %}
|
||||
import PaginatedList
|
||||
{% endif %}
|
||||
{% if class.needsDefaultValue %}
|
||||
from DefaultValueForOptionalParameters import DefaultValueForOptionalParameters
|
||||
{% endif %}
|
||||
|
||||
{% if class.dependencies %}
|
||||
##########
|
||||
|
||||
Reference in New Issue
Block a user