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

Standardize __repr__ for sheets and columns #2091

Merged
merged 3 commits into from
Oct 30, 2023
Merged

Conversation

cool-RR
Copy link
Contributor

@cool-RR cool-RR commented Oct 28, 2023

I find the current __repr__ for sheets confusing:

In [1]: vd.sheet
Out[1]: 2023-10-21-14-21-50-423073

It's not clear enough it's a sheet. I don't want to have to do type(x) to figure out what something is.

Here's how it looks like after this change:

In [1]: vd.sheet
Out[1]: <DirSheet: 2023-10-21-14-21-50-423073>

In [2]: vd.sheet.columns
Out[2]:
[<Column: directory>,
 <Column: filename>,
 <Column: abspath>,
 <Column: ext>,
 <Column: size>,
 <Column: modtime>,
 <Column: owner>,
 <Column: group>,
 <Column: mode>,
 <Column: filetype>]

@cool-RR
Copy link
Contributor Author

cool-RR commented Oct 28, 2023

I assume the CI failure is not related to my change.

@anjakefala
Copy link
Collaborator

Hey @cool-RR, could you give me examples of times when you would have found this change valuable? Especially the tagging that columns are a Column? It's an interesting proposal, but I'm trying to assess if we would also like it.

Before we could merge this in, we would definitely need to have a __str__, with the previous __repr__ text! A grep shows a bundle of places with something like basepath = str(self.source)

@cool-RR
Copy link
Contributor Author

cool-RR commented Oct 30, 2023

Hey @cool-RR, could you give me examples of times when you would have found this change valuable?

When I'm developing my scripts, I snoop around a live VisiData session to look at the different objects and how they relate to each other. When I see an object is just 2023-10-21-14-21-50-423073 I have to do an additional type() call to confirm that it's a sheet.

Especially the tagging that columns are a Column?

Columns are already tagged as columns. Currently their __repr__ shows up as Column:directory. I'm just making it look more standard, which is <Column: directory>. It could be argued that the colon should be dropped, or that there should be a colon but no space, or that there should be a comma instead. The pointy brackets however are important in my opinion, to make the boundaries from other objects clear.

Here's the similar representation for some built-in Python objects:

<sqlite3.Connection object at 0x7f3a20ca6c70>
<re.Match object; span=(0, 1), match='f'>
<_MainThread(MainThread, started 139858874212352)>

It's an interesting proposal, but I'm trying to assess if we would also like it.

Before we could merge this in, we would definitely need to have a __str__, with the previous __repr__ text! A grep shows a bundle of places with something like basepath = str(self.source)

Added, though I thought self.source points at something different than a sheet or a column.

@cool-RR cool-RR marked this pull request as ready for review October 30, 2023 08:04
@saulpw
Copy link
Owner

saulpw commented Oct 30, 2023

I thought self.source points at something different than a sheet or a column.

It can be either a Path (for a source sheet), or another Sheet (for a derived sheet or meta-sheet).

Copy link
Owner

@saulpw saulpw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, thanks @cool-RR!

@saulpw saulpw merged commit c7ace3a into saulpw:develop Oct 30, 2023
12 checks passed
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

Successfully merging this pull request may close these issues.

3 participants