mirror of
https://github.com/status-im/PyGithub.git
synced 2026-08-31 19:01:15 +00:00
Refactor switches in templates: step 1
This commit is contained in:
@@ -1,94 +1,27 @@
|
||||
{% for parameter in method.mandatoryParameters %}
|
||||
{% if parameter.type.cardinality == "scalar" %}
|
||||
|
||||
{% if parameter.type.simple %}
|
||||
{% if parameter.type.name == "string" %}
|
||||
assert isinstance( {{ parameter.name }}, ( str, unicode ) ), {{ parameter.name }}
|
||||
{% endif %}
|
||||
{% if parameter.type.name == "integer" %}
|
||||
assert isinstance( {{ parameter.name }}, int ), {{ parameter.name }}
|
||||
{% endif %}
|
||||
{% if parameter.type.name == "bool" %}
|
||||
assert isinstance( {{ parameter.name }}, bool ), {{ parameter.name }}
|
||||
{% endif %}
|
||||
{% if parameter.type.name == "dict" %}
|
||||
assert isinstance( {{ parameter.name }}, dict ), {{ parameter.name }}
|
||||
{% endif %}
|
||||
{% else %}
|
||||
assert isinstance( {{ parameter.name }}, {{ parameter.type.name }}.{{ parameter.type.name }} ), {{ parameter.name }}
|
||||
{% endif %}
|
||||
|
||||
{% else %}
|
||||
|
||||
{% if parameter.type.simple %}
|
||||
{% if parameter.type.name == "string" %}
|
||||
assert all( isinstance( element, ( str, unicode ) ) for element in {{ parameter.name }} ), {{ parameter.name }}
|
||||
{% endif %}
|
||||
{% if parameter.type.name == "integer" %}
|
||||
assert all( isinstance( element, int ) for element in {{ parameter.name }} ), {{ parameter.name }}
|
||||
{% endif %}
|
||||
{% if parameter.type.name == "bool" %}
|
||||
assert all( isinstance( element, bool ) for element in {{ parameter.name }} ), {{ parameter.name }}
|
||||
{% endif %}
|
||||
{% else %}
|
||||
assert all( isinstance( element, {{ parameter.type.name }}.{{ parameter.type.name }} ) for element in {{ parameter.name }} ), {{ parameter.name }}
|
||||
{% endif %}
|
||||
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
{% for parameter in method.optionalParameters %}
|
||||
{% if parameter.type.cardinality == "scalar" %}
|
||||
|
||||
{% if parameter.type.simple %}
|
||||
{% if parameter.type.name == "string" %}
|
||||
assert {{ parameter.name }} is GithubObject.NotSet or isinstance( {{ parameter.name }}, ( str, unicode ) ), {{ parameter.name }}
|
||||
{% endif %}
|
||||
{% if parameter.type.name == "integer" %}
|
||||
assert {{ parameter.name }} is GithubObject.NotSet or isinstance( {{ parameter.name }}, int ), {{ parameter.name }}
|
||||
{% endif %}
|
||||
{% if parameter.type.name == "bool" %}
|
||||
assert {{ parameter.name }} is GithubObject.NotSet or isinstance( {{ parameter.name }}, bool ), {{ parameter.name }}
|
||||
{% endif %}
|
||||
{% if parameter.type.name == "dict" %}
|
||||
assert {{ parameter.name }} is GithubObject.NotSet or isinstance( {{ parameter.name }}, dict ), {{ parameter.name }}
|
||||
{% endif %}
|
||||
{% else %}
|
||||
assert {{ parameter.name }} is GithubObject.NotSet or isinstance( {{ parameter.name }}, {{ parameter.type.name }}.{{ parameter.type.name }} ), {{ parameter.name }}
|
||||
{% endif %}
|
||||
|
||||
{% else %}
|
||||
|
||||
{% if parameter.type.simple %}
|
||||
{% if parameter.type.name == "string" %}
|
||||
assert {{ parameter.name }} is GithubObject.NotSet or all( isinstance( element, ( str, unicode ) ) for element in {{ parameter.name }} ), {{ parameter.name }}
|
||||
{% endif %}
|
||||
{% if parameter.type.name == "integer" %}
|
||||
assert {{ parameter.name }} is GithubObject.NotSet or all( isinstance( element, int ) for element in {{ parameter.name }} ), {{ parameter.name }}
|
||||
{% endif %}
|
||||
{% if parameter.type.name == "bool" %}
|
||||
assert {{ parameter.name }} is GithubObject.NotSet or all( isinstance( element, bool ) for element in {{ parameter.name }} ), {{ parameter.name }}
|
||||
{% endif %}
|
||||
{% else %}
|
||||
assert {{ parameter.name }} is GithubObject.NotSet or all( isinstance( element, {{ parameter.type.name }}.{{ parameter.type.name }} ) for element in {{ parameter.name }} ), {{ parameter.name }}
|
||||
{% endif %}
|
||||
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
|
||||
{% if method.variadicParameter %}
|
||||
{% if method.variadicParameter.type.name != "@todo" %}
|
||||
{% if method.variadicParameter.type.simple %}
|
||||
{% if method.variadicParameter.type.name == "string" %}
|
||||
assert all( isinstance( {{ method.variadicParameter.name }}, ( str, unicode ) ) for {{ method.variadicParameter.name }} in {{ method.variadicParameter.name }}s ), {{ method.variadicParameter.name }}s
|
||||
{% endif %}
|
||||
{% if parameter.type.name == "integer" %}
|
||||
assert all( isinstance( {{ method.variadicParameter.name }}, int ) for {{ method.variadicParameter.name }} in {{ method.variadicParameter.name }}s ), {{ method.variadicParameter.name }}s
|
||||
{% endif %}
|
||||
{% if parameter.type.name == "bool" %}
|
||||
assert all( isinstance( {{ method.variadicParameter.name }}, bool ) for {{ method.variadicParameter.name }} in {{ method.variadicParameter.name }}s ), {{ method.variadicParameter.name }}s
|
||||
{% endif %}
|
||||
{% else %}
|
||||
assert all( isinstance( {{ method.variadicParameter.name }}, {{ method.variadicParameter.type.name }}.{{ method.variadicParameter.type.name }} ) for {{ method.variadicParameter.name }} in {{ method.variadicParameter.name }}s ), {{ method.variadicParameter.name }}s
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
{% for parameter in method.mandatoryParameters %}
|
||||
{% if parameter.type.name != "@todo" %}
|
||||
{% with simple_or_complex=parameter.type.simple|yesno:"simple,complex" %}
|
||||
{% with template_name="GithubObject.IsInstance."|add:parameter.type.cardinality|add:"."|add:simple_or_complex|add:".py" %}
|
||||
assert {% include template_name with variable=parameter.name type=parameter.type only %}, {{ parameter.name }}
|
||||
{% endwith %}
|
||||
{% endwith %}
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
|
||||
{% for parameter in method.optionalParameters %}
|
||||
{% if parameter.type.name != "@todo" %}
|
||||
{% with simple_or_complex=parameter.type.simple|yesno:"simple,complex" %}
|
||||
{% with template_name="GithubObject.IsInstance."|add:parameter.type.cardinality|add:"."|add:simple_or_complex|add:".py" %}
|
||||
assert {{ parameter.name }} is GithubObject.NotSet or {% include template_name with variable=parameter.name type=parameter.type only %}, {{ parameter.name }}
|
||||
{% endwith %}
|
||||
{% endwith %}
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
|
||||
{% if method.variadicParameter %}
|
||||
{% with simple_or_complex=method.variadicParameter.type.simple|yesno:"simple,complex" %}
|
||||
{% with template_name="GithubObject.IsInstance.list."|add:simple_or_complex|add:".py" %}
|
||||
assert {% include template_name with variable=method.variadicParameter.name|add:"s" type=method.variadicParameter.type only %}, {{ method.variadicParameter.name }}s
|
||||
{% endwith %}
|
||||
{% endwith %}
|
||||
{% endif %}
|
||||
|
||||
Reference in New Issue
Block a user