GitHub user leifurhauks opened a pull request:

    https://github.com/apache/tinkerpop/pull/360

    revise a mutable default kwarg on GraphTraversalSource

    previously, in the signature of GraphTraversalSource.__init__, the
    bytecode kwarg had a default value of `Bytecode()`. In python, mutable
    default kwargs are evaluated at definition time, not when the function
    is called. Thus, prior to this commit, the following script would print
    `True`:
    
    ```python
    from gremlin_python.structure import RemoteGraph
    from gremlin_python.process import GroovyTranslator
    
    graph = RemoteGraph(GroovyTranslator('g'), None)
    traversal_source1 = graph.traversal()
    traversal_source2 = graph.traversal()
    
    print(traversal_source1.bytecode is traversal_source2.bytecode)
    ```
    
    This means that if self.bytecode were mutated, the changes would
    persist, and future invocations of `GraphTraversalSource.__init__` would
    have created `GraphTraversalSource`s with dirty `self.bytecode`.

You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/leifurhauks/incubator-tinkerpop 
graph_traversal_mutable_kwarg

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/tinkerpop/pull/360.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #360
    
----
commit ab41c3f3ce1d0aa5567f8e7ddf128b5ac0944cdc
Author: Leifur Halldor Asgeirsson <[email protected]>
Date:   2016-07-08T16:36:51Z

    revise a mutable default kwarg on GraphTraversalSource
    
    previously, in the signature of GraphTraversalSource.__init__, the
    bytecode kwarg had a default value of `Bytecode()`. In python, mutable
    default kwargs are evaluated at definition time, not when the function
    is called. Thus, prior to this commit, the following script would print
    `True`:
    
    ```python
    from gremlin_python.structure import RemoteGraph
    from gremlin_python.process import GroovyTranslator
    
    graph = RemoteGraph(GroovyTranslator('g'), None)
    traversal_source1 = graph.traversal()
    traversal_source2 = graph.traversal()
    
    print(traversal_source1.bytecode is traversal_source2.bytecode)
    ```
    
    This means that if self.bytecode were mutated, the changes would
    persist, and future invocations of `GraphTraversalSource.__init__` would
    have created `GraphTraversalSource`s with dirty `self.bytecode`.

----


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

Reply via email to