Skip to content
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

Mutable Default Arguments #23

Closed
ruddyscent opened this issue Nov 29, 2023 · 1 comment
Closed

Mutable Default Arguments #23

ruddyscent opened this issue Nov 29, 2023 · 1 comment

Comments

@ruddyscent
Copy link
Contributor

The constructor of the Graph class has [] as the default value for the vertices parameter. However, this implementation would fail the following test code.

class TestGraph(unittest.TestCase):
    def setUp(self):
        self.graph = Graph()

    def test_add_vertex(self):
        self.assertEqual(self.graph.vertex_count, 0)

    def test_remove_vertex(self):
        self.graph.add_vertex('A')
        self.graph.add_vertex('B')
        self.graph.add_vertex('C')
        self.assertEqual(self.graph.vertex_count, 3)

The reason for this issue is explained in detail in the following link:

Mutable Default Arguments - Python Guide

@davecom
Copy link
Owner

davecom commented May 12, 2024

Thank you!

@davecom davecom closed this as completed May 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants