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

Should detect Table.with_columns() and warn the user #333

Closed
davidwagner opened this issue Sep 22, 2018 · 5 comments · Fixed by #402
Closed

Should detect Table.with_columns() and warn the user #333

davidwagner opened this issue Sep 22, 2018 · 5 comments · Fixed by #402

Comments

@davidwagner
Copy link
Member

A common error that I see from students is to write code like Table.with_columns('x', arr), when they should have used Table().with_columns('x', arr). I suggest we try to detect that.

I suspect we could add a check at the start of the with_column() method to issue an error if type(self)==str, or maybe more broadly if type(self)!=Table (as I don't think we expect anyone to subclass Table).

@adnanhemani
Copy link
Member

This seems a bit harder than it looks. Since the number of arguments checked is on runtime, the TypeError caused when someone uses Table.with_columns(..., ...) is thrown on the caller's side. - it never actually makes it to the receiver's end. Thus, we can't actually write code in the function to check the type of self unless we make the arguments into un-named arguments (which I'm quite. sure we don't want). Any other ideas, @davidwagner?

@davidwagner
Copy link
Member Author

with_columns uses vargs, so it seems like it should work:

    def with_columns(self, *labels_and_values, **formatter):

In particular, add something like this to the start of with_columns:

        if type(self)==str:
            raise TypeError('Use Table().with_columns() to create a new table, not Table.with_columns()')

or

        if not isinstance(self, Table):
            raise TypeError('Use Table().with_columns() to create a new table, not Table.with_columns()')

@adnanhemani
Copy link
Member

adnanhemani commented Jul 3, 2019

OH, I was looking at with_column rather than with_columns! So this is completely possible with with_columns, but not with with_column - but I'd say that the behavior should be identical (in relation to the warning due to the relationship between the methods). However, as noted above, this wouldn't be possible.

Do you think it'd be okay to put a check on with_columns and not with_column?

@papajohn
Copy link
Contributor

papajohn commented Jul 3, 2019 via email

@davidwagner
Copy link
Member Author

Yes, it's fine to put the check on with_columns and not with_column. This isn't changing any semantics or behavior; it's just adding a warning about one common student error. If we can't warn for all student errors, it's still useful to warn for some of them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants